package yx.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import yx.dao.BaseDaoInt;
import yx.model.SmSms;
import yx.vo.DatagridVO;

@Service("smsService")
public class SmsServiceImpl implements SmsServiceInt {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(SmsServiceImpl.class);

	private BaseDaoInt<SmSms> smsDao;

	public BaseDaoInt<SmSms> getSmsDao() {
		return smsDao;
	}

	@Autowired
	public void setSmsDao(BaseDaoInt<SmSms> smsDao) {
		this.smsDao = smsDao;
	}


	@Override
	public DatagridVO datagrid() {
		DatagridVO dg = new DatagridVO();
		String hql = "from SmSms t ";
		Map<String, Object> params = new HashMap<String, Object>();
		String totalHql = "select count(*) from SmSms";
		List<SmSms> l = smsDao.find(hql, params, 1, 1);
		dg.setTotal(smsDao.count(totalHql, params));
		dg.setRows(l);
		return dg;
	}

	
	@Override
	public void edit(SmSms sms) {
	    SmSms t = smsDao.get(SmSms.class, sms.getId());
		smsDao.update(t);
	}

	@Override
	public SmSms get() {
		return smsDao.get(SmSms.class, 1);
	}

}
